package com.xinfu.newproject.adapter.property_provider;

import android.widget.CheckBox;
import android.widget.CompoundButton;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.xinfu.newproject.R;
import com.xinfu.newproject.adapter.preperty_adapter.PropertyAdapter;
import com.xinfu.newproject.bean.TestPropertyPayCostBean;
import com.xinfu.newproject.entity.NormalMultipleEntity;
import com.xinfu.newproject.interface_.PropertyInterface;

import java.util.ArrayList;
import java.util.List;

/**
 * https://github.com/chaychan
 * @author ChayChan
 * @description: Text Img ItemProvider
 * @date 2018/3/30  11:39
 */
public class PropertyTwoProvider extends BaseItemProvider<NormalMultipleEntity, BaseViewHolder> implements PropertyInterface {

    private RecyclerView recyclerView;
    private PropertyAdapter propertyAdapter;
    private CheckBox checkBox;

    @Override
    public int viewType() {
        return PropertyMultipleItemRvAdapter.TYPE_PROPERTY_TWO;
    }

    @Override
    public int layout() {
        return R.layout.item_property_two;
    }

    @Override
    public void convert(BaseViewHolder helper, NormalMultipleEntity data, int position) {
        recyclerView = helper.getView(R.id.item_property_two_rv);
        checkBox = helper.getView(R.id.item_property_two_all_cb);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        List<TestPropertyPayCostBean> list = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            TestPropertyPayCostBean testPropertyPayCostBean = new TestPropertyPayCostBean();
            testPropertyPayCostBean.setPrice("¥ 10");
            testPropertyPayCostBean.setStringTime("2019年7月至9月");
            list.add(testPropertyPayCostBean);
        }
        List<Integer> typeList = new ArrayList<>();
        typeList.add(1);
        propertyAdapter = new PropertyAdapter(mContext, list);
        recyclerView.setAdapter(propertyAdapter);

        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

                for (int i = 0; i < list.size(); i++) {
                    list.get(i).setClickble(b);
                }
                propertyAdapter.notifyDataSetChanged();
            }
        });
//        helper.setText(R.id.tv, data.content);
//        if (position % 2 == 0) {
//            helper.setImageResource(R.id.iv, R.mipmap.ic_launcher);
//        }else{
//            helper.setImageResource(R.id.iv, R.mipmap.ic_launcher);
//        }
    }


    @Override
    public void setPropertyCheckBox(boolean propertyCheckBox) {
        if (checkBox != null) {
            checkBox.setChecked(propertyCheckBox);
        }
    }
}
